﻿IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[proc_Cleanup]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
    DROP PROCEDURE [proc_Cleanup];
GO

CREATE PROCEDURE [proc_Cleanup]
AS
BEGIN
	SET NOCOUNT ON		
	
	BEGIN TRAN
	
	INSERT accionHist (NumeroAccion, PromocionId, ParticipanteId, Ganador) 
	SELECT NumeroAccion, PromocionId, ParticipanteId, Ganador FROM accion	
		
	INSERT participanteHist (Nombre, Cedula, Telefono, Empresa)
	SELECT Nombre, Cedula, Telefono, Empresa FROM participante
		
	TRUNCATE TABLE accion
	DELETE participante
	DELETE cargaExcel

	DBCC CHECKIDENT('accion', RESEED, 1)
	DBCC CHECKIDENT('participante', RESEED, 1)
	DBCC CHECKIDENT('cargaExcel', RESEED, 1) 
		
	COMMIT TRAN
END
GO



